package cn.topevery.garden.wapi.controller;

import cn.topevery.garden.dal.logic.RubbishBinReportLogic;
import cn.topevery.garden.entity.dto.RubbishBinReportDTO;
import cn.topevery.garden.entity.po.RubbishBinReport;
import cn.topevery.garden.entity.query.RubbishBinReportQuery;
import cn.topevery.garden.entity.vo.RubbishBinReportVO;
import com.github.dozermapper.core.Mapper;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.util.ExcelUtil;
import hw.topevery.framework.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 垃圾桶满溢信息表
 *
 * @author code-generate
 * @date 2021-08-18
 */
@Api(tags = "垃圾桶满溢信息表")
@RestController
@RequestMapping("/rubbish")
public class RubbishBinReportController extends BaseController {


    @Autowired
    RubbishBinReportLogic rubbishBinReportLogic;

    @Autowired
    private Mapper mapper;

    /**
     * 获取垃圾桶满溢信息表分页列表
     *
     * @param query
     * @return
     */
    @ApiOperation(value = "获取垃圾桶满溢信息表页列表")
    @PostMapping("/listPage")
    public JsonResult<DataPager<RubbishBinReportVO>> listPage(@RequestBody RubbishBinReportQuery query) {
        return JsonResult.ok(rubbishBinReportLogic.listPage(query));
    }

    @ApiOperation(value = "保存")
    @PostMapping(value = "/saveOrUpdate")
    public JsonResult<?> saveOrUpdate(@RequestBody RubbishBinReportDTO dto) {
        rubbishBinReportLogic.saveOrUpdate(getUser().id.toString(), mapper.map(dto, RubbishBinReport.class));
        return JsonResult.ok();
    }

    @ApiOperation("导出垃圾桶满溢信息表信息")
    @GetMapping("/export")
    public void export(RubbishBinReportQuery query, HttpServletResponse response) {
        List<RubbishBinReportVO> list = rubbishBinReportLogic.listPage(query).records;
        ExcelUtil.exportExcel(list, "垃圾桶满溢信息表", "sheet1", RubbishBinReportVO.class, "垃圾桶满溢信息表", response);
    }

}
